//
//  MTNewClubDetailHeaderView.swift
//  MT
//
//  Created by ooops on 2020/5/11.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit
import MTCategory

class MTNewClubDetailHeaderView: UIView {
    
    public var model: MTClubRichListResultModel? {
        didSet {
            if let m = model {
                if let avator = m.href {
                    clubIconImageView.mtSetImage(avator, nil)
                }
                
                if let name = model?.name {
                    clubNameLabel.text = name
                }
                
                if let pushId = model?.pushId {
                    clubIDLabel.text = "ID:\(pushId)"
                }
                
                if let area = model?.area, let province = model?.province, let city = model?.city {
                    clubAreaLabel.text = province + "-" + city + "-" + area
                }
            }
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        makeConstraint()
        backgroundColor = UIColor(hex: 0xF4F4F4)
    }
    
    lazy var bgImageView: UIImageView = {
        let imageV = UIImageView()
        imageV.image = UIImage(named: "club-head-bg")
        return imageV
    }()
    
    lazy var clubIconImageView: UIImageView = {
        let imageV = UIImageView()
        imageV.layer.cornerRadius = 48
        imageV.layer.masksToBounds = true
        imageV.layer.borderColor = UIColor(hex: 0xF4F4F4).cgColor
        imageV.layer.borderWidth = 1
        imageV.image = UIImage(named: defaultPlaceholderIcon60x60)
        imageV.contentMode = .scaleAspectFill
        return imageV
    }()
    
    lazy var clubNameLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCSemiboldFont(16)
        l.textColor = UIColor.text.x1d1a1a
        return l
    }()
    
    lazy var clubIDLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCMediumFont(12)
        l.textColor = UIColor.text.x1d1a1a
        return l
    }()
    
    lazy var clubAreaLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCMediumFont(12)
        l.textColor = UIColor.text.x1d1a1a
        return l
    }()
    
    lazy var lineView: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor(hex: 0xe6e6e6)
        return v
    }()
    
    private func setupUI() {
        addSubview(bgImageView)
        addSubview(clubIconImageView)
        addSubview(clubNameLabel)
        addSubview(clubIDLabel)
        addSubview(clubAreaLabel)
        addSubview(lineView)
    }
    
    private func makeConstraint() {
        bgImageView.snp.makeConstraints { (make) in
            make.left.right.top.equalToSuperview()
            make.height.equalTo(120)
        }
        
        clubIconImageView.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.centerY.equalTo(bgImageView.snp.bottom).offset(20)
            make.size.equalTo(CGSize(width: 96, height: 96))
        }
        
        clubNameLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(clubIconImageView.snp.bottom).offset(10)
        }
        
        clubIDLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(clubNameLabel.snp.bottom).offset(2)
        }
        
        clubAreaLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(clubIDLabel.snp.bottom).offset(2)
        }
        
        lineView.snp.makeConstraints { (make) in
            make.bottom.equalToSuperview()
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.height.equalTo(1)
        }
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }


}
